package com.ewanghuiju.app.presenter.my;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.my.MyInfoSettingContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.http.response.BaseResponse;
import com.ewanghuiju.app.model.http.response.MyHttpResponse;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/16
 */
public class MyInfoSettingPresenter extends RxPresenter<MyInfoSettingContract.View> implements MyInfoSettingContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public MyInfoSettingPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void settingWxCard(String wx_card) {
        //设置微信号
        addSubscribe(mDataManager.settingWxCard(wx_card)
                .compose(RxUtil.<MyHttpResponse<BaseResponse>>rxSchedulerHelper())
                .compose(RxUtil.<BaseResponse>handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<BaseResponse>>(mView) {
                    @Override
                    public void onNext(Optional<BaseResponse> baseResponse) {
                        if (mView != null)
                            mView.settingWxCardSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }

    @Override
    public void settingNickname(String nickName) {
        //设置昵称 type == 2
        addSubscribe(mDataManager.userinfo_edit("2", "", nickName)
                .compose(RxUtil.<MyHttpResponse<BaseResponse>>rxSchedulerHelper())
                .compose(RxUtil.<BaseResponse>handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<BaseResponse>>(mView) {
                    @Override
                    public void onNext(Optional<BaseResponse> baseResponse) {
                        if (mView != null)
                            mView.settingNicknameSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }
}
